

package com.maoshi.shop.groupbuy.multishop.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.maoshi.shop.common.util.PageParam;
import com.maoshi.shop.groupbuy.comment.dto.GroupTeamDto;
import com.maoshi.shop.groupbuy.comment.model.GroupOrder;
import com.maoshi.shop.groupbuy.comment.model.GroupTeam;
import com.maoshi.shop.groupbuy.comment.service.GroupOrderService;
import com.maoshi.shop.groupbuy.comment.service.GroupTeamService;
import com.maoshi.shop.security.multishop.util.SecurityUtils;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 拼团团队表
 *
 * @author LGH
 * @date 2019-08-27 17:55:57
 */
@RestController
@AllArgsConstructor
@RequestMapping("/group/team")
public class GroupTeamController {

    private final GroupTeamService groupTeamService;

    private final GroupOrderService groupOrderService;


    /**
     * 分页查询
     *
     * @param page          分页对象
     * @param groupTeamDto  拼团团队表
     * @return 分页数据
     */
    @GetMapping("/page")
    public ResponseEntity<IPage<GroupTeamDto>> getGroupTeamPage(PageParam<GroupTeam> page, GroupTeamDto groupTeamDto) {
        groupTeamDto.setShopId(SecurityUtils.getShopUser().getShopId());
        IPage<GroupTeamDto> pageList = groupTeamService.getPage(page, groupTeamDto);
        return ResponseEntity.ok(pageList);
    }

    /**
     * 查看同团订单列表
     *
     * @param groupTeamId id
     * @return 同团订单列表
     */
    @GetMapping("/info/{groupTeamId}")
    public ResponseEntity<List<GroupOrder>> getById(@PathVariable("groupTeamId") Long groupTeamId) {
        List<GroupOrder> list = groupOrderService.list(new LambdaQueryWrapper<GroupOrder>()
                .eq(GroupOrder::getGroupTeamId, groupTeamId)
//                .eq(GroupOrder::getStatus, GroupOrderStatusEnum.SUCCESS.getCode())
        );
        return ResponseEntity.ok(list);
    }
}
